package DrawEngine
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.utils.Dictionary;
	//绘制单元
	public class MultipleImg
	{
		public var Infos:Dictionary;
		public var Pos:Point;
		public var FootPos:Point;
		public var Data:BitmapData;
		
		private var bmpW:int;
		private var bmpH:int;
				
		public function MultipleImg()
		{
			Infos = new Dictionary();
			Pos = new Point();
			FootPos = new Point();
		}
		
		public function AddByIndex(_part:String,_index:int):void
		{
			Infos[_part] = DrawManager.SinglePool[_index];
			var info:DrawInfo = Infos[_part];
			
			var tempW:int = info.xP + info.wRect;
		    if (tempW > bmpW)
			     bmpW = tempW;
			
			var tempH:int = info.yP + info.hRect;
			if (tempH > bmpH)
			    bmpH = tempH;
		}
		
		public function AddByInfo(_part:String,_info:DrawInfo):void
		{
			Infos[_part] = _info;
		}
				
		public function AddNewInfo(_part:String,_sourceName:String,_id:int,_xR:int,_yR:int,_wR:int,_hR:int,_xP:int,_yP:int):void  
		{
			var info:DrawInfo = new DrawInfo(_sourceName, _id, _xR, _yR, _wR, _hR, _xP, _yP);
			DrawManager.SinglePool[_id] = info;
			AddByInfo(_part, info);
		}
		
		public function Draw():void
		{
			Data = new BitmapData(bmpW, bmpH,true,0x0);
			for each(var item:DrawInfo in Infos)
			{
				if (item.IsDraw)
				{
					var bmp:BitmapData = DrawManager.SourcePool[item.Source];
				    Data.copyPixels(bmp, new Rectangle(item.xRect, item.yRect, item.wRect, item.hRect), new Point(item.xP, item.yP),null,null,true);
				}
			}
		}	
		
		public function DelPart(_part:String):void
		{
			Infos[_part].Clear();
		    Infos[_part] = null;
			Sort();
			Draw();
		}
				
		public function Sort():void
		{
			Infos.sort(SortDepth);
		}
		
		private function SortDepth(a:DrawInfo, b:DrawInfo):Number
		{
			return Number(a.depthRelative - b.depthRelative);
		}	
	}
}